package com.freda.oa.flow.run.model.impl;

import com.freda.oa.flow.run.model.itf.FlowHisTaskmodelItf;
import com.freda.oa.flow.run.vo.FlowRunInfoVo;
import com.freda.oa.flow.utl.FlowIdHelper;
import com.freda.oa.flow.utl.TimeUtil;

/**
 * 操作历史task
 * @author Rally
 *
 */
public class FlowHisTaskModelImpl extends FlowBaseModelImpl implements FlowHisTaskmodelItf {
	
	/* (non-Javadoc)
	 * @see com.freda.oa.flow.run.model.impl.FlowHisTaskmodelItf#addHisTask(com.freda.oa.flow.run.vo.FlowRunInfoVo)
	 */
	@Override
	public int addHisTask(FlowRunInfoVo runInfo)
	{
		
		String hisTaskId = FlowIdHelper.getHisTaskId();
		
		runInfo.setHisTaskId(hisTaskId);
		
		g4Dao.insert("FlowHisTask.add", runInfo);
		
		return 1;
	}
	
	/* (non-Javadoc)
	 * @see com.freda.oa.flow.run.model.impl.FlowHisTaskmodelItf#editHisTask(com.freda.oa.flow.run.vo.FlowRunInfoVo)
	 */
	@Override
	public int editHisTask(FlowRunInfoVo runInfo)
	{
		
		runInfo.setTaskDurationTime(TimeUtil.getDuration(runInfo.getTaskStartTime(), runInfo.getNowTime()));
		
		if(g4Dao.update("FlowHisTask.update", runInfo) != -1 )
		{
			return 1;
		}
		else
		{
			return 0;			
		}
	}
	
	/* (non-Javadoc)
	 * @see com.freda.oa.flow.run.model.impl.FlowHisTaskmodelItf#lockAssignee(com.freda.oa.flow.run.vo.FlowRunInfoVo)
	 */
	@Override
	public int lockAssignee(FlowRunInfoVo runInfo)
	{
		if(g4Dao.update("FlowHisTask.lockAssignee", runInfo) != -1)
		{
			return 1;
		}
		else
		{
			return 0;
		}
	}
	
	/* (non-Javadoc)
	 * @see com.freda.oa.flow.run.model.impl.FlowHisTaskmodelItf#unLockAssignee(com.freda.oa.flow.run.vo.FlowRunInfoVo)
	 */
	@Override
	public int unLockAssignee(FlowRunInfoVo runInfo)
	{
		if(g4Dao.update("FlowHisTask.unLockAssignee", runInfo) != -1)
		{
			return 1;
		}
		else
		{
			return 0;
		}
	}
	
	/* (non-Javadoc)
	 * @see com.freda.oa.flow.run.model.impl.FlowHisTaskmodelItf#editState(com.freda.oa.flow.run.vo.FlowRunInfoVo)
	 */
	@Override
	public int editState(FlowRunInfoVo runInfo)
	{
		if(g4Dao.update("FlowHisTask.updateState", runInfo) != -1)
		{
			return 1;
		}
		else
		{
			return 0;			
		}
	}

}
